package com.dat255.tentatime;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

/**
 * This our custom made arrayadapter, specially designed to be used with
 * exam objects, the adapter will allow the listview to show both 
 * coursid and coursename
 * @author Joseph
 *
 */
public class ExamAdapter extends ArrayAdapter<Exam>{
	
	//id of the row layout
	private int resource;
	
	/**
	 * Creates an examadapter with a custom row layout
	 * @param application context
	 * @param resource of row layout 
	 * @param arraylist containing exam objects
	 */
	public ExamAdapter(Context context, int rowresource, List<Exam> objects) {
		super(context, rowresource,  objects);
		resource = rowresource;
		
		
	}
	
	/**
	 * The listview will use the method to create a custom row with appropriate information
	 * to be used when displaying the row in the listview
	 */
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
	     	View v = convertView;
	        //retrieve the selected exam from the list (the inserted list from param)
	     	Exam exam = getItem(position);
	        
	     	
	     	//Set our custom rowlayout to be default in the listview
	        LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	        v = vi.inflate(resource, null);
	    
	        //Attach GUI components from the custom rowlayout	
	        TextView examID =(TextView) v.findViewById(R.id.textCourseID);
	        TextView examName =(TextView) v.findViewById(R.id.textCourseName);
	        
	        //Set the appropriate text in the row
	        examID.setText(exam.getCourseID());
	        examName.setText(exam.getCourseName());
	 
	        return v;
	    }


	
	}
	